package fun.util.daohelper.hibernate;

import fun.util.daohelper.expression.*;
import fun.util.daohelper.hibernate.expression.*;

import java.util.Map;
import java.util.HashMap;

/**
 * Author: binz
 * Date: Sep 6, 2006
 * Time: 10:36:50 AM
 */
public class ExpressionTransformerFactory {

    public static final ExpressionTransformerFactory INSTANCE = new ExpressionTransformerFactory();

    Map<Class<? extends SearchExpression>, ExpressionCriterionTransformer> converterTable;

    private ExpressionTransformerFactory() {
        converterTable = new HashMap<Class<? extends SearchExpression>, ExpressionCriterionTransformer>();
        converterTable.put( StartsWith.class, new StartsWithTransformer() );
        converterTable.put( Equals.class, new EqualTransformer() );
        converterTable.put( GreaterThan.class, new GreaterThanTransformer() );
        converterTable.put( LessThan.class, new LessThanTransformer() );
        converterTable.put( Or.class, new OrTransformer() );
        converterTable.put( And.class, new AndTransformer() );
    }

    public ExpressionCriterionTransformer getTransformer( Class<? extends SearchExpression> expressionType ) {
        return converterTable.get( expressionType );
    }
}
